package com.ruoyi.report_ljlm.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.dynamic.datasource.annotation.DSTransactional;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.report_ljlm.domain.bo.ReportLjlmYsdhdfjlbBaDetailBo;
import com.ruoyi.report_ljlm.domain.vo.ReportLjlmYsdhdfjlbBaDetailVo;
import com.ruoyi.report_ljlm.domain.ReportLjlmYsdhdfjlbBaDetail;
import com.ruoyi.report_ljlm.mapper.ReportLjlmYsdhdfjlbBaDetailMapper;
import com.ruoyi.report_ljlm.service.IReportLjlmYsdhdfjlbBaDetailService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 压实度试验检测记录（环刀法）详细Service业务层处理
 *
 * @author zyb
 * @date 2024-11-08
 */
@RequiredArgsConstructor
@Service
@DSTransactional
public class ReportLjlmYsdhdfjlbBaDetailServiceImpl implements IReportLjlmYsdhdfjlbBaDetailService {

    private final ReportLjlmYsdhdfjlbBaDetailMapper baseMapper;

    /**
     * 查询压实度试验检测记录（环刀法）详细
     */
    @Override
    public ReportLjlmYsdhdfjlbBaDetailVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询压实度试验检测记录（环刀法）详细列表
     */
    @Override
    public TableDataInfo<ReportLjlmYsdhdfjlbBaDetailVo> queryPageList(ReportLjlmYsdhdfjlbBaDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportLjlmYsdhdfjlbBaDetail> lqw = buildQueryWrapper(bo);
        Page<ReportLjlmYsdhdfjlbBaDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询压实度试验检测记录（环刀法）详细列表
     */
    @Override
    public List<ReportLjlmYsdhdfjlbBaDetailVo> queryList(ReportLjlmYsdhdfjlbBaDetailBo bo) {
        LambdaQueryWrapper<ReportLjlmYsdhdfjlbBaDetail> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportLjlmYsdhdfjlbBaDetail> buildQueryWrapper(ReportLjlmYsdhdfjlbBaDetailBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportLjlmYsdhdfjlbBaDetail> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getExcelId() != null, ReportLjlmYsdhdfjlbBaDetail::getExcelId, bo.getExcelId());
        lqw.eq(bo.getBaRowNumber() != null, ReportLjlmYsdhdfjlbBaDetail::getBaRowNumber, bo.getBaRowNumber());
        lqw.eq(StringUtils.isNotBlank(bo.getQuyzh()), ReportLjlmYsdhdfjlbBaDetail::getQuyzh, bo.getQuyzh());
        lqw.eq(StringUtils.isNotBlank(bo.getJutwz()), ReportLjlmYsdhdfjlbBaDetail::getJutwz, bo.getJutwz());
        lqw.eq(StringUtils.isNotBlank(bo.getQuysd()), ReportLjlmYsdhdfjlbBaDetail::getQuysd, bo.getQuysd());
        lqw.eq(StringUtils.isNotBlank(bo.getHuandbh()), ReportLjlmYsdhdfjlbBaDetail::getHuandbh, bo.getHuandbh());
        lqw.eq(StringUtils.isNotBlank(bo.getTujhdzl()), ReportLjlmYsdhdfjlbBaDetail::getTujhdzl, bo.getTujhdzl());
        lqw.eq(StringUtils.isNotBlank(bo.getHuandzl()), ReportLjlmYsdhdfjlbBaDetail::getHuandzl, bo.getHuandzl());
        lqw.eq(StringUtils.isNotBlank(bo.getTuzl()), ReportLjlmYsdhdfjlbBaDetail::getTuzl, bo.getTuzl());
        lqw.eq(StringUtils.isNotBlank(bo.getHuandrj()), ReportLjlmYsdhdfjlbBaDetail::getHuandrj, bo.getHuandrj());
        lqw.eq(StringUtils.isNotBlank(bo.getShimd()), ReportLjlmYsdhdfjlbBaDetail::getShimd, bo.getShimd());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh1()), ReportLjlmYsdhdfjlbBaDetail::getHeh1, bo.getHeh1());
        lqw.eq(StringUtils.isNotBlank(bo.getHeh2()), ReportLjlmYsdhdfjlbBaDetail::getHeh2, bo.getHeh2());
        lqw.eq(bo.getHeh1Id() != null, ReportLjlmYsdhdfjlbBaDetail::getHeh1Id, bo.getHeh1Id());
        lqw.eq(bo.getHeh2Id() != null, ReportLjlmYsdhdfjlbBaDetail::getHeh2Id, bo.getHeh2Id());
        lqw.eq(StringUtils.isNotBlank(bo.getHejstzl1()), ReportLjlmYsdhdfjlbBaDetail::getHejstzl1, bo.getHejstzl1());
        lqw.eq(StringUtils.isNotBlank(bo.getHejstzl2()), ReportLjlmYsdhdfjlbBaDetail::getHejstzl2, bo.getHejstzl2());
        lqw.eq(StringUtils.isNotBlank(bo.getHejgtzl1()), ReportLjlmYsdhdfjlbBaDetail::getHejgtzl1, bo.getHejgtzl1());
        lqw.eq(StringUtils.isNotBlank(bo.getHejgtzl2()), ReportLjlmYsdhdfjlbBaDetail::getHejgtzl2, bo.getHejgtzl2());
        lqw.eq(StringUtils.isNotBlank(bo.getShuizl1()), ReportLjlmYsdhdfjlbBaDetail::getShuizl1, bo.getShuizl1());
        lqw.eq(StringUtils.isNotBlank(bo.getShuizl2()), ReportLjlmYsdhdfjlbBaDetail::getShuizl2, bo.getShuizl2());
        lqw.eq(StringUtils.isNotBlank(bo.getHezl1()), ReportLjlmYsdhdfjlbBaDetail::getHezl1, bo.getHezl1());
        lqw.eq(StringUtils.isNotBlank(bo.getHezl2()), ReportLjlmYsdhdfjlbBaDetail::getHezl2, bo.getHezl2());
        lqw.eq(StringUtils.isNotBlank(bo.getGantzl1()), ReportLjlmYsdhdfjlbBaDetail::getGantzl1, bo.getGantzl1());
        lqw.eq(StringUtils.isNotBlank(bo.getGantzl2()), ReportLjlmYsdhdfjlbBaDetail::getGantzl2, bo.getGantzl2());
        lqw.eq(StringUtils.isNotBlank(bo.getHansl1()), ReportLjlmYsdhdfjlbBaDetail::getHansl1, bo.getHansl1());
        lqw.eq(StringUtils.isNotBlank(bo.getHansl2()), ReportLjlmYsdhdfjlbBaDetail::getHansl2, bo.getHansl2());
        lqw.eq(StringUtils.isNotBlank(bo.getHanslpjz()), ReportLjlmYsdhdfjlbBaDetail::getHanslpjz, bo.getHanslpjz());
        lqw.eq(StringUtils.isNotBlank(bo.getGanmd()), ReportLjlmYsdhdfjlbBaDetail::getGanmd, bo.getGanmd());
        lqw.eq(StringUtils.isNotBlank(bo.getYasd()), ReportLjlmYsdhdfjlbBaDetail::getYasd, bo.getYasd());
        lqw.eq(StringUtils.isNotBlank(bo.getTurlb()), ReportLjlmYsdhdfjlbBaDetail::getTurlb, bo.getTurlb());
        lqw.eq(StringUtils.isNotBlank(bo.getZuidgmd()), ReportLjlmYsdhdfjlbBaDetail::getZuidgmd, bo.getZuidgmd());
        lqw.eq(StringUtils.isNotBlank(bo.getBianh()), ReportLjlmYsdhdfjlbBaDetail::getBianh, bo.getBianh());
        return lqw;
    }

    /**
     * 新增压实度试验检测记录（环刀法）详细
     */
    @Override
    public Boolean insertByBo(ReportLjlmYsdhdfjlbBaDetailBo bo) {
        ReportLjlmYsdhdfjlbBaDetail add = BeanUtil.toBean(bo, ReportLjlmYsdhdfjlbBaDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改压实度试验检测记录（环刀法）详细
     */
    @Override
    public Boolean updateByBo(ReportLjlmYsdhdfjlbBaDetailBo bo) {
        ReportLjlmYsdhdfjlbBaDetail update = BeanUtil.toBean(bo, ReportLjlmYsdhdfjlbBaDetail.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportLjlmYsdhdfjlbBaDetail entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除压实度试验检测记录（环刀法）详细
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
